package xgrammar;

import java.util.Arrays;

import org.w3c.xqparser.SimpleNode;
import org.w3c.xqparser.XParserVisitor;

public class vxpPrintText implements XParserVisitor
{
    public static int indentAmount=3;

    public Object visit(SimpleNode sn, Object o)
    {
        Integer a=(Integer)o;
        String value=sn.getValue();
        char[] padding=new char[a*indentAmount];

        /* Ignore the START node */
        if (sn.toString().equals("START"))
        {
            sn.childrenAccept(this, o);
            return o;
        }

        Arrays.fill(padding, ' ');

        if ((value!=null) && (value.length()>0))
            System.out.print(new String(padding)+sn.toString()+" "+value.toString()+"\n");
        else
            System.out.print(new String(padding)+sn.toString()+"\n");

        sn.childrenAccept(this, a+1);

        return o;
    }
}
